<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>系统设置测试</title>
</head>

<body>
  <div><span>时间显示：</span><span id="time"></span></div>
  </br>
  <div><span>消息提示：</span><span id="tips"></span></div>
  </br>
  <div>
    <span>语音合成：</span>
    <span>
      <input type="button" onclick="playVoice()" value="调用语音合成" />
      <input type="button" onclick="playVoiceAdd()" value="添加发声缓存" />
      <input type="button" onclick="playVoiceGet()" value="获取发声缓存" />
      <input type="button" onclick="playVoiceDelete()" value="删除发声缓存" />
      <input type="button" onclick="playDi()" value="发出提示声滴" />
      <input type="button" onclick="playVoiceInterval()" value="4s定时语音测试" />
      <input type="button" onclick="clearVoiceInterval()" value="清除定时语音测试" />
    </span>
  </div>
  </br>
  <div>
    <span>设置缓存：</span>
    <span>
      <input type="button" onclick="SetCache()" value="设置缓存" />
      <input type="button" onclick="GetCache()" value="获取缓存" />
    </span>
  </div>
  </br>
  </br>
  <div>
    <span>门灯控制：</span>
    <span>
      <input type="button" onclick="setLamp(2, 1)" value="数字灯开" />
      <input type="button" onclick="setLamp(2, 0)" value="数字灯关" />
      <input type="button" onclick="setLamp(3, 1)" value="门条灯开" />
      <input type="button" onclick="setLamp(3, 0)" value="门条灯关" />
    </span>
  </div>
  </br>
  <div>
    <span>德卡读卡：</span>
    <span>
<!--      <input type="button" onclick="readCard(0)" value="打开USB(0)" />-->
      <input type="button" onclick="readCard(1)" value="就诊卡(1)" />
      <input type="button" onclick="readCard(2)" value="社保卡(2" />
      <input type="button" onclick="readCard(3)" value="身份证(3)" />
      <input type="button" onclick="readCard(5)" value="身份证(5)" />
    </span>
  </div>
  </br>
  <div>
    <span>隔2秒读持续9秒读卡：</span>
    <span>
<!--      <input type="button" onclick="readCard(0)" value="打开USB(0)" />-->
      <input type="button" onclick="readCardLoop(8, 1, 2)" value="就诊卡(1)" />
      <input type="button" onclick="readCardLoop(8, 2, 2)" value="社保卡(2" />
      <input type="button" onclick="readCardLoop(8, 3, 2)" value="身份证(3)" />
      <input type="button" onclick="readCardLoop(8, 5, 2)" value="身份证(5)" />
    </span>
  </div>
  </br>
  <div>
    <span>WebView重新加载：</span>
    <span>
      <input type="button" onclick="webViewGC()" value="WebView重新加载" />
    </span>
  </div>
  <div>
    <span>调用打印机：</span>
    <span>
<!--      <input type="button" onclick="printNew()" value="美松打印机" />-->
      <input type="button" onclick="printAgain()" value="新打印机" />
    </span>
  </div>
  </br>
  </br>
  <div>
    <span>调用系统设置：</span>
    <span>
      <input type="button" onclick="voiceChange(1)" value="音量设置(+)" />
      <input type="button" onclick="voiceChange(0)" value="音量设置(-)" />
      <input type="button" onclick="deviceControl(2)" value="设备重启" />
      <input type="button" onclick="deviceControl(1)" value="设备关机" />
      <input type="button" onclick="deviceControl(180)" value="设备定时开关机(180s后关机)" />
    </span>
  </div>
  </br>
  <div>
    <span>认证信息：</span>
    <span>
      <input type="button" onclick="getInfo()" value="查看认证信息" />
    </span>
  </div>
  </br>
  <div>
    <span>android 通过js调用web：</span>
    <span>
      <div><span>扫码内容：</span><span id="scanText"></span></div>
      <div><span>发声结束后通知内容：</span><span id="voiceRes"></span></div>
      <div><span>卡片读取内容：</span><span id="cardTest"></span></div>
    </span>
  </div>
</body>
<script>
  ShowTime();
  function ShowTime() {
    try {
      var obj, n, y, r, s, f, x, d;
      var weekday = new Array(7)
      weekday[0] = "日"
      weekday[1] = "一"
      weekday[2] = "二"
      weekday[3] = "三"
      weekday[4] = "四"
      weekday[5] = "五"
      weekday[6] = "六"
      obj = new Date();
      n = obj.getYear() + 1900;
      if (obj.getMonth() < 9) {
        y = "0" + (obj.getMonth() + 1);
      } else {
        y = obj.getMonth() + 1;
      }
      if (obj.getDate() < 10) {
        r = "0" + obj.getDate();
      } else {
        r = obj.getDate();
      }
      x = "星期" + weekday[obj.getDay()];
      if (obj.getHours() < 10) {
        s = "0" + obj.getHours();
      } else {
        s = obj.getHours();
      }
      if (obj.getMinutes() < 10) {
        f = "0" + obj.getMinutes();
      } else {
        f = obj.getMinutes();
      }
      if (obj.getSeconds() < 10) {
        d = "0" + obj.getSeconds();
      } else {
        d = obj.getSeconds();
      }
      var ymd = n + "年" + y + "月" + r + "日";
      var time = s + ":" + f + ":" + d;
      document.getElementById("time").innerHTML = ymd + " " + time + " " + x;
      setTimeout(ShowTime, 900)
    } catch (ex) {

    }
  }
  function playVoice() {
    var json = {
      'num': 1,//发声次数
      'dataStr': "请A3号张三到101诊室就诊"
    };
    try {
      var res = IPSJavaObject.PlayYZSVoice(JSON.stringify(json));
    } catch (e) {
      document.getElementById("tips").innerHTML = "发声失败，暂不支持语音合成";
    }
  }
  var voiceInterval;
  function playVoiceInterval() {
    var json = {
      'num': 1,//发声次数
      'dataStr': "4秒定时发声测试"
    };
    try {
      IPSJavaObject.playDi();
      setTimeout(function () {
        var res = IPSJavaObject.PlayYZSVoice(JSON.stringify(json));
      }, 1200)
    } catch (e) {
      document.getElementById("tips").innerHTML = "发声失败，暂不支持语音合成";
    }
    voiceInterval = setTimeout(playVoiceInterval, 4000);
  }
  function clearVoiceInterval() {
    clearTimeout(voiceInterval);
  }
  function playVoiceAdd() {
    var json = {
      'num': 1,//发声次数
      'dataStr': "请A3号张三到101诊室就诊"
    };
    try {
      var res = IPSJavaObject.playVoiceAdd(JSON.stringify(json));
    } catch (e) {
      document.getElementById("tips").innerHTML = "添加发声缓存失败";
    }
  }
  function playVoiceGet() {
    try {
      var res = IPSJavaObject.playVoiceGet();
      document.getElementById("tips").innerHTML = "发声缓存获取内容为：" + res;
    } catch (e) {
      document.getElementById("tips").innerHTML = "获取缓存内容失败";
    }
  }
  function playVoiceDelete() {
    try {
      var json = {
        'num': 1,//发声次数
        'dataStr': "这是测试添加发声缓存内容"
      };
      var res = IPSJavaObject.playVoiceDelete(JSON.stringify(json));
      document.getElementById("tips").innerHTML = "删除发声缓存返回提示：" + res;
    } catch (e) {
      document.getElementById("tips").innerHTML = "删除发声缓存内容失败";
    }
  }
  function playDi() {
    try {
      IPSJavaObject.playDi();
    } catch (e) {
      document.getElementById("tips").innerHTML = "发声didi失败";
    }
  }
  function SetCache() {
    try {
      IPSJavaObject.SetCache("test", "这是测试页面缓存");
    } catch (e) {
      document.getElementById("tips").innerHTML = "添加缓存失败";
    }
  }
  function setLamp(pos, res) {
    try {
      IPSJavaObject.setLamp(pos, res);
    } catch (e) {
      document.getElementById("tips").innerHTML = "失败";
    }
  }
  function GetCache() {
    try {
      var res = IPSJavaObject.GetCache("test");
      document.getElementById("tips").innerHTML = "获取缓存内容为：" + res;
    } catch (e) {
      document.getElementById("tips").innerHTML = "获取缓存失败";
    }
  }
  function readCard(code) {
    try {
      IPSJavaObject.readCard(code);
    } catch (e) {
      document.getElementById("tips").innerHTML = "开启卡片读取失败";
    }
  }
  function readCardLoop(allTime, code, formTime) {
    try {
      IPSJavaObject.readCardLoop(allTime, code, formTime);
    } catch (e) {
      document.getElementById("tips").innerHTML = "开启卡片读取失败";
    }
  }
  function webViewGC() {
    try {
      IPSJavaObject.webViewGC(code);
    } catch (e) {
      document.getElementById("tips").innerHTML = "webView GC 重新加载失败";
    }
  }
  function printNew() {
    var array = [
      { "type": 2, "dataBold": false, "dataPosition": 1, "dataSize": 1, "dataStr": "中国农业银行\n\n办理业务(一)\n\n" },
      { "type": 3, "dataBold": true, "dataPosition": 0, "dataSize": 1, "dataStr": "324334432" },
      { "type": 3, "dataBold": false, "dataPosition": 0, "dataSize": 0, "dataStr": "您前面有 10 人等候，请注意叫号\n\n欢迎光临！我们将竭诚为你服务。\n" },
      { "type": 5, "dataStr": "这是二维码内容", "dataPosition": 1, "marginLeft": 25, "size": 6 },
      { "type": 1, "dataBold": false, "dataPosition": 0, "size": 2, "dataStr": "3、这是空行。" },
      { "type": 4, "dataPosition": 0, "width": 2, "height": 100, "dataStr": "68990986678085" },
      { "type": 1, "dataBold": false, "dataPosition": 0, "size": 2, "dataStr": "3、这是空行。" }
    ]
    try {
      IPSJavaObject.printNew(JSON.stringify(array));
    } catch (e) {
      document.getElementById("tips").innerHTML = "调用打印失败";
    }
  }
  function printAgain() {
    var array = [
      { "type": 2, "dataBold": false, "dataPosition": 1, "dataSize": 1, "dataStr": "中国农业银行\n\n办理业务(一)\n\n" },
      { "type": 3, "dataBold": true, "dataPosition": 0, "dataSize": 1, "dataStr": "324334432" },
      { "type": 3, "dataBold": false, "dataPosition": 0, "dataSize": 0, "dataStr": "您前面有 10 人等候，请注意叫号\n\n欢迎光临！我们将竭诚为你服务。\n" },
      { "type": 5, "dataStr": "这是二维码内容", "dataPosition": 1, "marginLeft": 25, "size": 6 },
      { "type": 1, "dataBold": false, "dataPosition": 0, "size": 2, "dataStr": "3、这是空行。" },
      { "type": 4, "dataPosition": 0, "width": 2, "height": 100, "dataStr": "68990986678085" },
      { "type": 1, "dataBold": false, "dataPosition": 0, "size": 2, "dataStr": "3、这是空行。" }
    ]
    try {
      IPSJavaObject.printAgain(JSON.stringify(array), 1);
    } catch (e) {
      document.getElementById("tips").innerHTML = "调用打印失败";
    }
  }
  function voiceChange(state) {
    try {
      IPSJavaObject.voiceChange(state);
    } catch (e) {
      document.getElementById("tips").innerHTML = "设置设备音量失败";
    }
  }
  function deviceControl(state) {
    try {
      IPSJavaObject.deviceControl(state);
    } catch (e) {
      if (state == 1) {
        document.getElementById("tips").innerHTML = "设备控制设置关机失败";
      } else if (state == 2) {
        document.getElementById("tips").innerHTML = "设备控制设置重启失败";
      } else {
        document.getElementById("tips").innerHTML = "设备控制设置定时开关机失败";
      }
    }
  }
  function OnScan(code) {
    document.getElementById("scanText").innerHTML = code;
  }
  function getVoiceRes() {
    document.getElementById("voiceRes").innerHTML = "发声完成";
  }
  function OnCardRead(card) {
    document.getElementById("cardTest").innerHTML = card;
  }

  function getInfo() {
    IPSJavaObject.toSysInfo()
  }
</script>

</html>